library(stm)

# These are the STM results for the random binary (we called "blue team").
#load("stm_blue_bio.RDS")
#load("stm_blue_eng.RDS")


# Lines 9 to 29 take the STM object and makes them usable for further analysis. 
#load("ac_inspir_bio_fit.RDS")
#load("ac_inspir_eng_fit.RDS")

#gend <- ac_inspir_bio_fit$settings$covariates$X[,2]
#math_perc <- ac_inspir_bio_fit$settings$covariates$X[,4]
#gpa_perc <- ac_inspir_bio_fit$settings$covariates$X[,3]
#read_perc <- ac_inspir_bio_fit$settings$covariates$X[,5]

#gend_e <- ac_inspir_eng_fit$settings$covariates$X[,2]
#math_perc_e <- ac_inspir_eng_fit$settings$covariates$X[,4]
#gpa_perc_e <- ac_inspir_eng_fit$settings$covariates$X[,3]
#read_perc_e <- ac_inspir_eng_fit$settings$covariates$X[,5]

#bio_effects <- estimateEffect(1:102 ~ gend + math_perc + gpa_perc + read_perc,
#                              ac_inspir_bio_fit,
#                              uncertainty = "Global")

#eng_effects <- estimateEffect(1:107 ~ gend_e + math_perc_e + gpa_perc_e + 
#                                read_perc_e,
#                              ac_inspir_eng_fit,
#                              uncertainty = "Global")

# Loading the data from the STM to prep the STM results for the figures/analysis.
load("bio_effects.RDS")
load("eng_effects.RDS")

tmp_final <- plot(eng_effects, covariate = "gend_e", topics = c(1,
                                                                5,
                                                                7,
                                                                8,
                                                                10,
                                                                12,
                                                                13,
                                                                16,
                                                                18,
                                                                28,
                                                                33,
                                                                35,
                                                                39,
                                                                43,
                                                                44,
                                                                46,
                                                                51,
                                                                53,
                                                                58,
                                                                63,
                                                                64,
                                                                69,
                                                                72,
                                                                74,
                                                                75,
                                                                77,
                                                                82,
                                                                83,
                                                                86,
                                                                87,
                                                                88,
                                                                89,
                                                                92,
                                                                93,
                                                                94,
                                                                97,
                                                                98,
                                                                99,
                                                                100,
                                                                106),
                  model = ac_inspir_eng_fit, method = "difference", cov.value1 = 0,
                  cov.value2 = 1,
                  xlab = "More Male ... More Female",
                  main = "Effect of Gender, All Engineering Applicants", xlim = c(-0.0175, 0.0175),
                  labeltype = "custom",
                  custom.labels = c("Understanding the world",
                                    "Right answers",
                                    "Reading fiction",
                                    "Marine biology",
                                    "Math tutoring",
                                    "Physics concepts",
                                    "    Art",
                                    "Physics laws",
                                    "Engineering career",
                                    "AP tests",
                                    "Quantum physics",
                                    "Video games",
                                    "Astronomy",
                                    "World history",
                                    "Environmental science",
                                    "Internet technology",
                                    "Mathematics",
                                    "Diseases, cancer",
                                    "Favorite subject",
                                    "Foreign languages",
                                    "Microbiology",
                                    "Computer science",
                                    "Vehicle project",
                                    "Enjoyed class",
                                    "Circuits",
                                    "Women in science",
                                    "Disciplines and people",
                                    "Medical practice",
                                    "Learning to code",
                                    "Puzzles   ",
                                    "Research programs",
                                    "Coding, apps",
                                    "Public speaking",
                                    "Right or wrong answers",
                                    "Aeronautics",
                                    "Chemistry experiements",
                                    "Family, women",
                                    "Scientific discovery",
                                    "Spanish language and culture",
                                    "The universe"))
dev.off()


tmp_bio <- plot(bio_effects, covariate = "gend", topics = c(  1,
                                                              8,
                                                              12,
                                                              15,
                                                              21,
                                                              23,
                                                              24,
                                                              26,
                                                              31,
                                                              32,
                                                              33,
                                                              36,
                                                              37,
                                                              42,
                                                              47,
                                                              54,
                                                              55,
                                                              56,
                                                              57,
                                                              63,
                                                              68,
                                                              76,
                                                              80,
                                                              81,
                                                              88,
                                                              97,
                                                              101),
                model = ac_inspir_bio_fit, method = "difference", cov.value1 = 0,
                cov.value2 = 1,
                xlab = "More Male ... More Female",
                main = "Effect of Gender, All Biology Applicants", xlim = c(-0.025, 0.025),
                labeltype = "custom",
                custom.labels = c("Classroom troubles",
                                  "Writing and reading",
                                  "Hospital volunteers",
                                  "Teams and communities",
                                  "Astronomy",
                                  "Medical experiences",
                                  "Time words",
                                  "Academic biology",
                                  "Plants, nature",
                                  "Wanting to help",
                                  "Building computers",
                                  "Ancient history",
                                  "Problem solving",
                                  "Data and logic",
                                  "Favorite subject",
                                  "Movies, writing",
                                  "Spanish language",
                                  "History, the past",
                                  "Reading, libraries",
                                  "Sport medicine",
                                  "High school classes",
                                  "World events",
                                  "Speaking Spanish",
                                  "Mental health",
                                  "Dissecting animals",
                                  "Reading books, articles",
                                  "Science fair, volcanoes"))
dev.off()


